package ru.alperez.model;

import org.json.JSONException;
import org.json.JSONObject;

public class Creator {
	private String name = "";
	private String description = "";
	private String imei = "";
	private String device = "";
	private String model = "";
	
	
	public static Creator fromJSON(JSONObject jCreator) {
		Creator ret = new Creator();
		try {
			ret.name = jCreator.optString("name");
			ret.description = jCreator.optString("description");
			ret.imei = jCreator.optString("imei");
			ret.device = jCreator.optString("device");
			ret.model = jCreator.optString("model");
		} catch (NullPointerException e) { }
		return ret;
	}
	
	public boolean equal(Creator c) {
		if (c == null) return false;
		
		if (name!=null) {
			if (!name.equals(c.getName()))
				return false;
		} else if (c.getName()!=null) {
			return false;
		}
		if (description!=null) {
			if (!description.equals(c.getDescription()))
				return false;
		} else if (c.getDescription()!=null) {
			return false;
		}
		if (imei!=null) {
			if (!imei.equals(c.getImei()))
				return false;
		} else if (c.getImei()!=null) {
			return false;
		}
		if (device!=null) {
			if (!device.equals(c.getDevice()))
				return false;
		} else if (c.getDevice()!=null) {
			return false;
		}
		if (model!=null) {
			if (!model.equals(c.getModel()))
				return false;
		} else if (c.getModel()!=null) {
			return false;
		}
		
		return true;
	}
	
	
	public JSONObject toJSON() throws JSONException {
		JSONObject ret = new JSONObject();
		ret.put("name", name);
		ret.put("description", description);
		ret.put("imei", imei);
		ret.put("device", device);
		ret.put("model", model);
		return ret;
	}
	
	// ------ Accessors ------
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getImei() {
		return imei;
	}
	public void setImei(String imei) {
		this.imei = imei;
	}
	public String getDevice() {
		return device;
	}
	public void setDevice(String device) {
		this.device = device;
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
}
